<?php
namespace App\Http\Middleware;
use Closure;
use Route;
class CheckPermission
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next,$model)
    {
        $routeName = Route::currentRouteName();
     //   $permission = config('admin.permissions.'.$model,'');
        $this->check($request,$model);
        return $next($request);
    }

    private function check($request,$permission)
    {
        if (!$request->user()->can($permission)) {
            abort(500,403);
           // abort(403);
        }
    }
}
